package pl.planito.manager;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import pl.planito.entity.User;
import pl.planito.user.info.UserDataBridge;
import pl.planito.user.managament.IUserManager;

/**
 * Session Bean implementation class UserManager
 */
@Stateless
public class UserManagerImpl implements IUserManager{
	@PersistenceContext 
	private EntityManager entityManager;
    /**
     * Default constructor. 
     */
    public UserManagerImpl() {
        // TODO Auto-generated constructor stub
    }

	public List<UserDataBridge> getUsers() {
		// TODO Auto-generated method stub
		return null;
	}

	public UserDataBridge getUser(String id) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public UserDataBridge findUser(String id) {
		User user = (User)this.entityManager.createNamedQuery("findUser").getSingleResult();
		
		return toUserDataBridge(user);
	}
	
	private UserDataBridge toUserDataBridge(User user){
		UserDataBridge dataBridge = new UserDataBridge();
		//dataBridge.setBlocked(user.getBlocked());
		dataBridge.setEmail(user.getEmail());
		dataBridge.setLogin(user.getLogin());
		dataBridge.setName(user.getName());
		dataBridge.setPassword(user.getPassword());
		dataBridge.setSurname(user.getSurname());
		return dataBridge;
	}

}
